data modify storage vs:system temp.ChainFM.command set from storage vs:system chain.list[-1].command
data modify storage vs:system temp.ChainFM.team set from storage vs:system chain.list[-2].command

execute if data storage vs:system temp.ChainFM{team:"blue"} run data modify storage vs:system temp.ChainFM.player set from entity @r[team=red] UUID
execute if data storage vs:system temp.ChainFM{team:"red"} run data modify storage vs:system temp.ChainFM.player set from entity @r[team=blue] UUID

function vs:chain/pop/command_modulated/command with storage vs:system temp.ChainFM

data remove storage vs:system temp.ChainFM